float4x4 World;
float4x4 View;
float4x4 Projection;
float4 Color;
float Time;
float g_leaftype;
// TODO: add effect parameters here.
uniform extern texture UserTexture;
uniform extern texture LeafTextureB;

struct VS_OUTPUT
{
    float4 position  : POSITION;
    float2 textureCoordinate : TEXCOORD0;
};

sampler textureSampler = sampler_state
{
    Texture = <UserTexture>;
    mipfilter = LINEAR;  
    AddressU = Wrap;
    AddressV = Wrap;
};
sampler textureSamplerB = sampler_state
{
    Texture = <LeafTextureB>;
    mipfilter = LINEAR;  
    AddressU = Wrap;
    AddressV = Wrap;
};
 

struct VertexShaderInput
{
    float4 Position : POSITION0;
    float2 Texcoord : TEXCOORD0;
    float3 Normal : NORMAL0;

    // TODO: add input channels such as texture
    // coordinates and vertex colors here.
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float2 Texcoord : TEXCOORD0;

    // TODO: add vertex shader outputs such as colors and texture
    // coordinates here. These values will automatically be interpolated
    // over the triangle, and provided as input to your pixel shader.
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;
    float4 offset = 0.05 * float4(sin(Time +  World._41), sin(Time  + World._42), 0, 0);
    float4 worldPosition = mul(input.Position + offset, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);
	output.Texcoord = input.Texcoord;
	output.Texcoord.y = 1-output.Texcoord.y;
    // TODO: add your vertex shader code here.

    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{ 
    float4 co = Color;
    co += .51;
    co.w = 1;
    
return lerp( tex2D(textureSampler, input.Texcoord), tex2D(textureSamplerB, input.Texcoord), g_leaftype);
 
}

float4 psFruit(VertexShaderOutput input) : COLOR0
{
float4 col = saturate( tex2D(textureSampler, input.Texcoord) );

	return  col;
}
float4 psFruitGlow(VertexShaderOutput input) : COLOR0
{
float4 col = saturate( tex2D(textureSampler, input.Texcoord) );
col.w *= sin(Time * 4) * 0.25 + 0.75;
	return  col;
}
technique Technique1
{
    pass Pass1
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
    pass Pass2
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 psFruit();
    }
    pass Pass4
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 psFruitGlow();
    }
}
